home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWStream / Sources / FWASinks.cpp next >
Encoding:
Text File  |  1994-04-21  |  7.7 KB  |  244 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWASinks.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWASINKS_H
  13. #include "FWASinks.h"
  14. #endif
  15.  
  16. #ifndef FWPRIMEM_H
  17. #include "FWPriMem.h"
  18. #endif
  19.  
  20. #ifndef   FWPRIDEB_H
  21. #include "FWPriDeb.h"
  22. #endif
  23.  
  24. #pragma segment FWStream
  25.  
  26. //========================================================================================
  27. //    CLASS FW_CSink
  28. //========================================================================================
  29.  
  30. //----------------------------------------------------------------------------------------
  31. // FW_CSink::FW_CSink
  32. //----------------------------------------------------------------------------------------
  33.  
  34. FW_CSink::FW_CSink()
  35. {
  36. }
  37.  
  38. //----------------------------------------------------------------------------------------
  39. // FW_CSink::FW_CSink
  40. //----------------------------------------------------------------------------------------
  41.  
  42. FW_CSink::FW_CSink(const FW_CSink& sink)
  43. {
  44. }
  45.  
  46. //----------------------------------------------------------------------------------------
  47. // FW_CSink::~FW_CSink
  48. //----------------------------------------------------------------------------------------
  49.  
  50. FW_CSink::~FW_CSink()
  51. {
  52. }
  53.  
  54. //----------------------------------------------------------------------------------------
  55. // FW_CSink::operator=
  56. //----------------------------------------------------------------------------------------
  57.  
  58. FW_CSink& FW_CSink::operator=(const FW_CSink& sink)
  59. {
  60.     return (*this);
  61. }
  62.  
  63.  
  64.  
  65. //========================================================================================
  66. // CLASS FW_CRandomAccessSink
  67. //========================================================================================
  68.  
  69. //----------------------------------------------------------------------------------------
  70. //    FW_CRandomAccessSink::FW_CRandomAccessSink
  71. //----------------------------------------------------------------------------------------
  72.  
  73. FW_CRandomAccessSink::FW_CRandomAccessSink() :
  74.     FW_CSink()
  75. {
  76. }
  77.  
  78. //----------------------------------------------------------------------------------------
  79. //    FW_CRandomAccessSink::FW_CRandomAccessSink
  80. //----------------------------------------------------------------------------------------
  81.  
  82. FW_CRandomAccessSink::FW_CRandomAccessSink(const FW_CRandomAccessSink& sink) :
  83.     FW_CSink(sink)
  84. {
  85. }
  86.  
  87. //----------------------------------------------------------------------------------------
  88. //    FW_CRandomAccessSink::~FW_CRandomAccessSink
  89. //----------------------------------------------------------------------------------------
  90.  
  91. FW_CRandomAccessSink::~FW_CRandomAccessSink()
  92. {
  93. }
  94.  
  95. //----------------------------------------------------------------------------------------
  96. // FW_CRandomAccessSink::GetReadableBytes
  97. //----------------------------------------------------------------------------------------
  98.  
  99. long FW_CRandomAccessSink::GetReadableBytes() const
  100. {
  101.     return GetLength() - GetPosition();
  102. }
  103.  
  104. //----------------------------------------------------------------------------------------
  105. // FW_CRandomAccessSink::operator=
  106. //----------------------------------------------------------------------------------------
  107.  
  108. FW_CRandomAccessSink& FW_CRandomAccessSink::operator=(const FW_CRandomAccessSink& sink)
  109. {
  110.     return (*this);
  111. }
  112.  
  113.  
  114. //========================================================================================
  115. //    CLASS FW_CMemorySink
  116. //========================================================================================
  117.  
  118. //----------------------------------------------------------------------------------------
  119. // FW_CMemorySink::FW_CMemorySink
  120. //----------------------------------------------------------------------------------------
  121.  
  122. FW_CMemorySink::FW_CMemorySink(void* buffer, long capacity, long initialPosition) :
  123.     FW_CRandomAccessSink(),
  124.     fBuffer((char*)buffer),
  125.     fCapacity(capacity),
  126.     fPosition(initialPosition)
  127. {
  128.     FW_ASSERT(fPosition < fCapacity);
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. // FW_CMemorySink::~FW_CMemorySink
  133. //----------------------------------------------------------------------------------------
  134.  
  135. FW_CMemorySink::~FW_CMemorySink()
  136. {
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. // FW_CMemorySink::Read
  141. //----------------------------------------------------------------------------------------
  142.  
  143. void FW_CMemorySink::Read(void* destination,
  144.                           long count)
  145. {
  146.     FW_ASSERT(count >= 0);
  147.     FW_ASSERT(fPosition + count <= fCapacity);
  148.     FW_PrimitiveCopyMemory(fBuffer + fPosition, destination, count);
  149.     fPosition += count;
  150. }
  151.  
  152. //----------------------------------------------------------------------------------------
  153. // FW_CMemorySink::ReadPeek
  154. //----------------------------------------------------------------------------------------
  155.  
  156. const void * FW_CMemorySink::ReadPeek(long & availableReadBytes)
  157. {
  158.     availableReadBytes = fCapacity - fPosition;
  159.     return fBuffer + fPosition;
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. // FW_CMemorySink::ReadPeekAdvance
  164. //----------------------------------------------------------------------------------------
  165.  
  166. void FW_CMemorySink::ReadPeekAdvance(long bytesRead)
  167. {
  168.     FW_ASSERT(bytesRead >= 0);
  169.     FW_ASSERT(fPosition + bytesRead <= fCapacity);
  170.     fPosition += bytesRead;
  171. }
  172.  
  173. //----------------------------------------------------------------------------------------
  174. // FW_CMemorySink::GetWritableBytes
  175. //----------------------------------------------------------------------------------------
  176.  
  177. long FW_CMemorySink::GetWritableBytes() const
  178. {
  179.     return GetReadableBytes();
  180. }
  181.  
  182. //----------------------------------------------------------------------------------------
  183. // FW_CMemorySink::Write
  184. //----------------------------------------------------------------------------------------
  185.  
  186. void FW_CMemorySink::Write(const void* source,
  187.                            long count)
  188. {
  189.     FW_ASSERT(count >= 0);
  190.     FW_ASSERT(fPosition + count <= fCapacity);
  191.     FW_PrimitiveCopyMemory(source, fBuffer + fPosition, count);
  192.     fPosition += count;
  193. }
  194.  
  195. //----------------------------------------------------------------------------------------
  196. // FW_CMemorySink::WritePeek
  197. //----------------------------------------------------------------------------------------
  198.  
  199. void * FW_CMemorySink::WritePeek(long& availableWriteBytes)
  200. {
  201.     availableWriteBytes = fCapacity - fPosition;
  202.     return fBuffer + fPosition;
  203. }
  204.  
  205. //----------------------------------------------------------------------------------------
  206. // FW_CMemorySink::WritePeekAdvance
  207. //----------------------------------------------------------------------------------------
  208.  
  209. void FW_CMemorySink::WritePeekAdvance(long bytesWritten)
  210. {
  211.     FW_ASSERT(bytesWritten >= 0);
  212.     FW_ASSERT(fPosition + bytesWritten <= fCapacity);
  213.     fPosition += bytesWritten;
  214. }
  215.  
  216. //----------------------------------------------------------------------------------------
  217. // FW_CMemorySink::GetLength
  218. //----------------------------------------------------------------------------------------
  219.  
  220. long FW_CMemorySink::GetLength() const
  221. {
  222.     return fCapacity;
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------
  226. // FW_CMemorySink::GetPosition
  227. //----------------------------------------------------------------------------------------
  228.  
  229. long FW_CMemorySink::GetPosition() const
  230. {
  231.     return fPosition;
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. // FW_CMemorySink::SetPosition
  236. //----------------------------------------------------------------------------------------
  237.  
  238. void FW_CMemorySink::SetPosition(long position)
  239. {
  240.     FW_ASSERT(position >= 0);
  241.     FW_ASSERT(position <= fCapacity);
  242.     fPosition = position;
  243. }
  244.